package com.ysy.tz.mfg.service;

import com.ysy.tz.core.utils.SQLUtils;
import com.ysy.tz.core.utils.SessionUtils;
import com.ysy.tz.mfg.dao.UserDao;
import com.ysy.tz.mfg.entity.UserEntity;

public class UserEditService {
    public UserEditService() {
    }

    public boolean addUser(UserEntity userEntity) {
        return (Boolean)SQLUtils.executeSQLWithReturn(UserDao.class, (userDao) -> {
            try {
                UserEntity loginUser = (UserEntity)SessionUtils.getAttribute(SessionUtils.CURRENT_USER);
                userEntity.setEnterpriseId(loginUser.getEnterpriseId());
                userEntity.setIsEnabled("Y");
                userEntity.setIsBuiltIn("N");
                userEntity.setCreateUserCode(loginUser.getUserCode());
                userEntity.setCreateUserName(loginUser.getUserName());
                int result = userDao.save(userEntity);
                return result > 0;
            } catch (Exception var4) {
                var4.printStackTrace();
                return false;
            }
        });
    }

    public boolean editUser(UserEntity userEntity) {
        return (Boolean)SQLUtils.executeSQLWithReturn(UserDao.class, (userDao) -> {
            try {
                UserEntity loginUser = (UserEntity)SessionUtils.getAttribute(SessionUtils.CURRENT_USER);
                userEntity.setEditUserCode(loginUser.getUserCode());
                userEntity.setEditUserName(loginUser.getUserName());
                int result = userDao.updateUser(userEntity);
                return result > 0;
            } catch (Exception var4) {
                var4.printStackTrace();
                return false;
            }
        });
    }
}
